package com.tuanzi.loan.business.service.member.impl;

import com.tuanzi.loan.business.entity.member.LoanMemberPrice;
import com.tuanzi.loan.business.repository.member.LoanMemberPriceRepository;
import com.tuanzi.loan.business.service.member.LoanMemberPriceService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.service.CommonServiceImpl;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.member.LoanMemberPriceRequest;
import com.tuanzi.loan.vo.response.member.LoanMemberPriceResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * User: liangZongXi
 * Create time: 10:49 2019/4/3
 * Description:
 */

@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class LoanMemberPriceServiceImpl extends CommonServiceImpl<LoanMemberPrice, Long> implements LoanMemberPriceService {

    private final LoanMemberPriceRepository loanMemberPriceRepository;

    @Autowired
    public LoanMemberPriceServiceImpl(LoanMemberPriceRepository loanMemberPriceRepository) {
        this.loanMemberPriceRepository = loanMemberPriceRepository;
    }

    @Override
    public Page<LoanMemberPriceResponse> list(PageSearcher<LoanMemberPriceRequest> pageSearcher) {
        return loanMemberPriceRepository.list(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
    }

    @Override
    public LoanMemberPrice findByProductId(String productId) {
        if(StringUtils.isBlank(productId)){
            return null;
        }
        return loanMemberPriceRepository.findByProductId(productId);
    }

    @Override
    protected JpaRepository<LoanMemberPrice, Long> getRepository() {
        return loanMemberPriceRepository;
    }
}
